package rootkit

import (
	"fmt"
	"io/ioutil"
)

type DevCheck struct {
	BaseDir		string

	IgnoreDev 	map[string]struct{}

	Stat 		StatInfo
}

func (d *DevCheck) DevRcCheck() error {
	d.Stat.Total = 0
	d.Stat.Errors = 0

	// 设置ignore
	d.IgnoreDev["MAKEDEV"] = struct{}{}
	d.IgnoreDev["README.MAKEDEV"] = struct{}{}
	d.IgnoreDev["MAKEDEV.README"] = struct{}{}
	d.IgnoreDev[".udevdb"] = struct{}{}
	d.IgnoreDev[".udev.tdb"] = struct{}{}
	d.IgnoreDev[".initramfs-tools"] = struct{}{}
	d.IgnoreDev["MAKEDEV.local"] = struct{}{}
	d.IgnoreDev[".initramfs"] = struct{}{}
	d.IgnoreDev["oprofile"] = struct{}{}
	d.IgnoreDev["fd"] = struct{}{}
	d.IgnoreDev["cgroup"] = struct{}{}

	//filePath := fmt.Sprintf("%s/dev", d.BaseDir)

	if d.Stat.Errors == 0 {
		fmt.Sprintf("No problem detected on the /dev directory. Analyzed %d files.", d.Stat.Total)
	}
	return nil
}

func (d *DevCheck) readDevDir(filePath string) error {
	if filePath == "" {
		return nil
	}

	fileInfos, err := ioutil.ReadDir(filePath)
	if err != nil {
		return err
	}
	for _, item := range fileInfos {
		if item.Name() == "." || item.Name() == ".." {
			continue
		}
		d.Stat.Total++


	}


	return nil
}
